package com.yaoli.ajob;

import java.util.Arrays;

/**
 * Created by will on 2017/7/8.
 */
public class _628_MaximumProductofThreeNumbers {
    public int maximumProduct(int[] nums) {
        Arrays.sort(nums);

        int max = Integer.MIN_VALUE;

        int a = nums[0] * nums[nums.length - 1] * nums[nums.length - 2] ;
        int b = nums[0] * nums[nums.length - 1] * nums[1] ;

        max = Math.max(max,a);
        max = Math.max(max,b);

        for(int i = 2; i < nums.length ; i ++){
            int res = nums[i]*nums[i-1]*nums[i-2];
            max = Math.max(max,res);
        }

        return max;
    }
}
